#include<bits/stdc++.h>
using namespace std;

const int N=10010;
int f[N],a[N],n,flag=0;

int pd(){
  for(int i=2;i<=n;i++){
    int t=a[i]-f[i]-f[i-1];
    if(t<0||t>1)return 0;
    else f[i+1]=t;
  }
  if(f[n]+f[n-1]!=a[n])return 0;
  return 1;
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    if(a[i]>3)flag=1;
  }
  if(a[1]>2||a[n]>2||flag==1){
    cout<<"0"<<endl;
    return 0;
  }
  int res=0;
  if(a[1]==2){
    f[1]=1;
    f[2]=1;
    res+=pd();
  }
  else if(a[1]==0) {
    f[1]=0;
    res+=pd();
  }
  else if(a[1]==1) {
    f[1]=1;
    res+=pd();
    memset(f,0,sizeof(f));
    f[2]=1;
    res+=pd();
  }
  cout<<res<<endl;

  return 0;
}